package com.supermarket.web.controller.supermarket;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.supermarket.business.domain.SupermarketProduct;
import com.supermarket.business.dto.SupermarketProductDTO;
import com.supermarket.business.vo.SupermarketProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.supermarket.common.annotation.Log;
import com.supermarket.common.core.controller.BaseController;
import com.supermarket.common.core.domain.AjaxResult;
import com.supermarket.common.enums.BusinessType;
import com.supermarket.business.service.ISupermarketProductService;
import com.supermarket.common.utils.poi.ExcelUtil;
import com.supermarket.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 商品Controller
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@RestController
@RequestMapping("/supermarket/product")
public class SupermarketProductController extends BaseController
{
    @Resource
    private ISupermarketProductService sysProductService;

    /**
     * 查询商品列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(SupermarketProductDTO SupermarketProductDTO)
    {
        startPage();
        SupermarketProduct SupermarketProduct = new SupermarketProduct();
        BeanUtils.copyProperties(SupermarketProductDTO, SupermarketProduct);
        List<SupermarketProduct> list = sysProductService.selectSysProductList(SupermarketProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
    @PreAuthorize("@ss.hasPermi('supermarket:product:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SupermarketProduct SupermarketProduct)
    {
        List<SupermarketProduct> list = sysProductService.selectSysProductList(SupermarketProduct);
        ExcelUtil<SupermarketProduct> util = new ExcelUtil<SupermarketProduct>(SupermarketProduct.class);
        util.exportExcel(response, list, "商品数据");
    }

    /**
     * 获取商品详细信息
     */
    @PreAuthorize("@ss.hasPermi('supermarket:product:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(sysProductService.selectSysProductVOByProductId(productId));
    }

    /**
     * 新增商品
     */
    @PreAuthorize("@ss.hasPermi('supermarket:product:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(SupermarketProductDTO SupermarketProductDTO)
    {
        SupermarketProduct SupermarketProduct = new SupermarketProduct();
        BeanUtils.copyProperties(SupermarketProductDTO, SupermarketProduct);
        return toAjax(sysProductService.insertSysProduct(SupermarketProduct));
    }

    /**
     * 修改商品
     */
    @PreAuthorize("@ss.hasPermi('supermarket:product:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(SupermarketProductDTO SupermarketProductDTO)
    {
        SupermarketProduct SupermarketProduct = new SupermarketProduct();
        BeanUtils.copyProperties(SupermarketProductDTO, SupermarketProduct);
        return toAjax(sysProductService.updateSysProduct(SupermarketProduct));
    }

    /**
     * 删除商品
     */
    @PreAuthorize("@ss.hasPermi('supermarket:product:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(sysProductService.deleteSysProductByProductIds(productIds));
    }
}
